Using Git and GitHub is a great way to code collaborativly on projects. Please use this guide to get set up or as reference for git commands.
Go to git-scm.com/download and click on the “Windows” link under "Downloads on the main screen.
Update Git Bash
git update-git-for-windows
Go to github.com and click either on the large green button “Sign Up for GitHub” in the middle of the page or the small button “Sign Up” in the top right corner of the page.
C:\PROJECT-CLONES. This also makes the pathways shorter because it doesn’t inlcude your name.git clone <repo HTTPS path> where <repo HTTPS path> is the url from step 1; press Enter
git pull origin <branch>
<branch> you will be working on is main or master. The branch you are working on will show up in blue font in parenthesis in the git bash window. Pulling the most recent code is essential for collaborative coding, this helps prevents conflicts to the code if edits are made on multiple different versions. git status
git diff
git diff will show all changes for any file, if you only want to look at changes for a specific file use git diff <file>.git add --all will stage all files that are listed after the git status command
git add <file> will add only a specific file
git add *.R will add all files that have a .R extension (stage all R scripts)
git status command again, files that were in red font should now be in green font, indicating that they have been staged and are ready to be committed.git commit -m '<message>' where <message> is a short description of the edits.git push origin <branch> Most often the <branch> you will be working on is main or master. Originally, the default branch was always called ‘master’. Starting in fall 2020, GitHub changed the default branch name to be ‘main’.git pull origin <branch>; to update codegit status to view which files have changedgit diff to view line by line changesgit add --all to stage all filesgit commit -m '<message>' to commit changesgit push origin <branch> to send changes to GitHub so others can access
Change the remote link with the following:
git remote set-url origin <new-url>
Check to see if the link has been updated using:
git config --get remote.origin.url
The URL should now be the updated version. main or master branch<file> must include file name and the extension (i.e. ‘test.sas’ or ‘test.R’ not just ‘test’)| command | description |
|---|---|
git add --all
|
stage ALL files that have been changed/added/deleted |
git add <file>
|
Stage a specific <file>
|
git checkout -b <branch>
|
Create a new <branch> and switch to that <branch>
|
git checkout <branch>
|
Switch to a specific <branch>
|
git checkout <file>
|
Revert <file> to most recent commit on local repo
|
git commit -m '<message>'
|
Commit changes with short <message>
|
git diff --stat --cached origin/<branch>
|
List of files that have been commited (list of files that will be included in next git push)
|
git diff <file>
|
View changes for a specific <file>; if you just use git diff all changes for all files will be shown. If you have a lot of changes it will end with an (END) on the screen, to quit this screen press the Q key
|
git fetch origin <branch>
|
See if there are any changes/updates from a specific <branch>; could do this prior to git pull
|
git log -<numb>
|
View a list of the most recent <numb> commits; e.g. git log -2 will show 2 commits
|
git pull origin <branch>
|
Pull from specific <branch>; will generally be main or master
|
git push origin <branch>
|
Push to specific <branch>; will generally be main or master
|
git reset
|
Undo git add; will un-stage all files; can also use git reset <file> to unstage specific file
|
git status
|
see which files have been changed/added/deleted on working branch |
What if I want to ignore any differences on my clone and ‘reset’ to the version on GitHub?
git fetch origin <branch>git reset --hard origin/<branch>This should be done rarely because any changes you have worked on will not be saved.
In addition to git command, you can use UNIX commands in the bash window.
| command | description |
|---|---|
cd ..
|
Move up one folder; e.g. go from C:/Documents/<folder> to C:/Documents
|
cd <folder>
|
Move down into a specific folder; e.g. go from C:/Documents to C:/Documents/<folder>
|
ls -l
|
View files in current folder and their recent mondification |